package model

import (
	"api-getaway/basic/config"
	"gorm.io/gorm"
)

// 商品表
type Shop struct {
	gorm.Model
	Name  string  `gorm:"type:varchar(20);not null;comment:'商品名称'"`
	Price float64 `gorm:"type:decimal(10,2);not null;comment:'商品价格'"`
	Stock int     `gorm:"type:int;not null;comment:'商品库存'"`
}

func (s *Shop) CreateShop() error {
	return config.DB.Debug().Create(&s).Error
}

// 橱窗分类表
type DisplayWindow struct {
	gorm.Model
	Name string `gorm:"type:varchar(20);not null;comment:'橱窗分类名称'"`
}

func (d *DisplayWindow) CreateDisplayWindow() error {
	return config.DB.Debug().Create(&d).Error
}

// 橱窗商品表
type ShowcaseProducts struct {
	gorm.Model
	Name             string  `gorm:"type:varchar(20);not null;comment:'橱窗商品名称'"`
	Sales            int     `gorm:"type:int;not null;comment:'橱窗商品销量'"`
	BelongingExperts string  `gorm:"type:varchar(20);not null;comment:'所属达人'"`
	DisplayWindowId  int     `gorm:"type:int;not null;comment:'橱窗分类ID'"`
	Price            float64 `gorm:"type:decimal(10,2);not null;comment:'橱窗商品价格'"`
}

func (sp *ShowcaseProducts) CreateShowcaseProducts() error {
	return config.DB.Debug().Create(&sp).Error
}

// 用户订单表
type UserOrder struct {
	gorm.Model
	OrderId int    `gorm:"type:int;not null;comment:'订单ID'"`
	ShopId  int    `gorm:"type:int;not null;comment:'商品ID'"`
	UserId  int    `gorm:"type:int;not null;comment:'用户ID'"`
	Time    string `gorm:"type:datetime;not null;comment:'下单时间'"`
	Status  int    `gorm:"type:int;not null;comment:'订单状态'"`
}

func (u *UserOrder) CreateUserOrder() error {
	return config.DB.Debug().Create(&u).Error
}
